package com.wuji1626.spark.dependency

import org.apache.spark.{SparkConf, SparkContext}

object RDD_BloodRelationship {

  def main(args: Array[String]): Unit = {

    // Step1: 准备环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    // Step2: 血缘
    val lines = sc.textFile("datas/word.txt")
    // 打印 lines 的血缘关系
    println(lines.toDebugString)
    println("************************")
    val words = lines.flatMap(_.split(" "))
    println(words.toDebugString)
    println("************************")
    val wordOne = words.map(word => (word, 1))
    println(wordOne.toDebugString)
    println("************************")
    val wordSum = wordOne.reduceByKey(_ + _)
    println(wordSum.toDebugString)
    println("************************")
    val array = wordSum.collect()
    array.foreach(println)
    // Step3: 关闭环境
    sc.stop()
  }
}
